<template>
	<view class="wrap">
		<view class="item" @click="goDetail(item)" v-for="(item, index) in cardInfoList" :key="index">
			<image class="icon" :src="item.image" mode=""></image>
			<view class="info">
				<view class="text">
					<text class="name">{{item.bankName}}</text>
					<text class="type">储蓄卡</text>
				</view>
				<view class="desc" v-if="item.type == 2">可提现二类户余额</view>
				<view class="desc" v-if="item.type == 1">可提现电子钱包余额</view>
				<view class="number">**** **** **** {{formatBank(item.cardNo)}}</view>
			</view>
			<view class="default" v-if="item.isDefault == 1">默认</view>
		</view>
		<view class="bottom" @click="goAddCard">
			<image src="@/static/icon_blue_add.png" mode=""></image>
			<text>添加银行卡</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardInfoList: [],
			}
		},
		onLoad() {
			this.queryDriverJzbCardNo()
		},
		onShow() {
			this.queryDriverJzbCardNo()
		},
		methods: {
			queryDriverJzbCardNo() {
				this.wxRequest({
					url: `${this.API}/myWallet/queryDriverJzbCardNo`,
					method: 'POST',
					title: '加载中...',
					success: res => {
						this.cardInfoList = res.data.data
					}
				});
			},
			goAddCard() {
				uni.navigateTo({
					url: './addCard'
				})
			},
			formatBank(bank) {
				// return bank.replace(/[\s]/g, 'string').replace(/(\d{4})(?=\d)/g, "$1 ")
				return bank.slice(-4)
			},
			goDetail(item) {
				let info = JSON.stringify(item)
				uni.navigateTo({
					url: `./cardDetail?info=${info}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap{
		padding: 16rpx;
	}
	.bottom{
		background: #fff;
		padding: 24rpx 0;
		box-sizing: border-box;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;
		font-weight: 400;
		color: #000000;
		border-radius: 12rpx;
		image{
			width: 76rpx;
			height: 76rpx;
			margin-right: 24rpx;
		}
	}
	.item{
		padding: 24rpx 24rpx 24rpx 120rpx;
		background: #fff;
		border-radius: 12rpx;
		margin-bottom: 16rpx;
		overflow: hidden;
		position: relative;
		.default{
			position: absolute;
			top: 0;
			right: 0;
			background: #F1F1F1;
			font-size: 24rpx;
			font-weight: 400;
			color: #9E9E9E;
			padding: 8rpx 24rpx;
			border-bottom-left-radius: 12rpx;
		}
		.info{
			margin-top: 12rpx;
			.number{
				font-size: 40rpx;
				font-weight: 500;
				color: #333333;
				padding: 24rpx 0 12rpx;
			}
			.text{
				display: flex;
				align-items: center;
				color: #333333;
				.name{
					font-size: 34rpx;
					font-weight: 500;
					margin-right: 24rpx;
				}
				.type{
					font-size: 24rpx;
					font-weight: 500;
				}
			}
			.desc{
				font-size: 24rpx;
				font-weight: 400;
				color: #9E9E9E;
			}
		}
		.icon{
			position: absolute;
			top: 32rpx;
			left: 24rpx;
			width: 60rpx;
			height: 60rpx;
		}
	}
</style>